package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsContractBasicVo;
import org.dromara.nursing.domain.bo.MsContractBasicBo;
import org.dromara.nursing.service.IMsContractBasicService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 合同信息
 *
 * @author Lion Li
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/contractBasic")
public class MsContractBasicController extends BaseController {

    private final IMsContractBasicService msContractBasicService;

    /**
     * 查询合同信息列表
     */
    // @SaCheckPermission("nursing:contractBasic:list")
    @GetMapping("/list")
    public TableDataInfo<MsContractBasicVo> list(MsContractBasicBo bo, PageQuery pageQuery) {
        return msContractBasicService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出合同信息列表
     */
    // @SaCheckPermission("nursing:contractBasic:export")
    @Log(title = "合同信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsContractBasicBo bo, HttpServletResponse response) {
        List<MsContractBasicVo> list = msContractBasicService.queryList(bo);
        ExcelUtil.exportExcel(list, "合同信息", MsContractBasicVo.class, response);
    }

    /**
     * 获取合同信息详细信息
     *
     * @param contractId 主键
     */
    // @SaCheckPermission("nursing:contractBasic:query")
    @GetMapping("/{contractId}")
    public R<MsContractBasicVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long contractId) {
        return R.ok(msContractBasicService.queryById(contractId));
    }

    /**
     * 新增合同信息
     */
    // @SaCheckPermission("nursing:contractBasic:add")
    @Log(title = "合同信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsContractBasicBo bo) {
        return toAjax(msContractBasicService.insertByBo(bo));
    }

    /**
     * 修改合同信息
     */
    // @SaCheckPermission("nursing:contractBasic:edit")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsContractBasicBo bo) {
        return toAjax(msContractBasicService.updateByBo(bo));
    }

    /**
     * 删除合同信息
     *
     * @param contractIds 主键串
     */
    // @SaCheckPermission("nursing:contractBasic:remove")
    @Log(title = "合同信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contractIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] contractIds) {
        return toAjax(msContractBasicService.deleteWithValidByIds(List.of(contractIds), true));
    }
}
